define(function(require) {

  var _ = require('underscore')
  var createEl = require('../util/createEl')

  var EventEmitter = require('eventemitter3')
  var t = require('t')
  
  function Node(el, opts) {
    this.el = el;
    
    this.props = _.extend({
      x: 0,
      y: 0,
      w: 100,
      h: 100,
      rotate: 0
    }, opts);

    EventEmitter.call(this)

    var self = this;

    this.el.addEventListener('mouseover', function() {
      self.emit('hover')
    })

    this.el.addEventListener('mouseout', function() {
      self.emit('unhover')
    })

    this.el.addEventListener('click', function(e) {
      self.emit('active')
    })
    
    if (typeof this.dispatch !== 'function') {

      //事件分发到以id关联的绘制实例和文字浮层
      Node.prototype.dispatch = function(type, opts) {
        switch (type) {
          case "translate":
            break;
          case "scale":
            break;
          case "rotate":
            break;
        }
      };

      Node.prototype.getConnectPoint = function(direction) {
        var props = this.props;
        var point = {}
        switch (direction) {
          case 'e':
          default:
            point = {
              x: props.x + props.width,
              y: props.y + props.height / 2
            };
            break;
          case 's':
            point = {
              x: props.x + props.width / 2,
              y: props.y + props.height
            };
            break;
          case 'w':
            point = {
              x: props.x,
              y: props.y + props.height / 2
            };
            break;
          case 'n':
            point = {
              x: props.x + props.width / 2,
              y: props.y
            };
            break;
        }
        return point;
      }
    }
  }

  Node.init = function(root, id, opts) {
    var el = createEl('div', opts)
    el.id = '__node__' + id;
    el.className = "node";
    el.setAttribute('title', '__node__' + id);

    root.appendChild(el)

    var node = new Node(el, opts);
    node.id = id;
    return node;
  }

  t.inherits(Node, EventEmitter);

  return Node
})